class ReposKeys
  attr_accessor :github

  def initialize(github)
    @github = github
  end

  def listKeys(repo, user=nil)
    username = user == nil ? @github.username : user
    @github.get('repos/%s/%s/keys' % [username, repo])
  end

  def getKey(repo, id, user=nil)
    username = user == nil ? @github.username : user
    @github.get('repos/%s/%s/keys/%s' % [username, repo, id])
  end

  def createKey(repo, title, key, user=nil)
    username = user == nil ? @github.username : user
    params = {
        :title => title,
        :key => key
    }
    data = params.to_json
    @github.post('repos/%s/%s/keys' % [username, repo], data)
  end

  def editKey(repo, id, title=nil, key=nil, user=nil)
    username = user == nil ? @github.username : user
    params = {
        :title => title,
        :key => key
    }
    params = @github.removeEmptyParams(params)
    data = params.to_json
    @github.patch('repos/%s/%s/keys/%s' % [username, repo, id], data)
  end

  def deleteKey(repo, id, user=nil)
    username = user == nil ? @github.username : user
    @github.delete('repos/%s/%s/keys/%s' % [username, repo, id])
  end
end
